<include file="../header" />
<body class="J_scroll_fixed">
<script type="text/javascript" src="/Template/js/qrcode/jquery.qrcode.min.js"></script>
<style type="text/css">
    .btn,.btn-danger,.btn-info,.btn-success,.btn-warning{
        width: 80px;
        /*height: 18px;*/
        padding: 2px 0px 2px 0px;
        margin: 1px 0px 1px 0px;
    }
    select{
        width: auto
    }
</style>
<script type="text/javascript">
    function del(id, name) {
        if (!confirm("是否作废CP码【" + name + "】?")) {
            return false;
        }
        var url = "/admin/coupon/remove?id=" + id;
        window.location.href = url;
    }
    function showQrcode(url) {
        if(url == 0){
            $("#qrcode").html("");
        }
        jQuery('#qrcode').qrcode(url);
    }
    $(function() {

        $("input[name=checkAll]").click(function() {
            var checkboxs = $("input.checkItem");
            if($("input[name=checkAll]").is(':checked')) {
                for(var i = 0 ;i<checkboxs.length;i++) {
                    checkboxs[i].checked = true;
                }
            }else{
                for(var i = 0 ;i<checkboxs.length;i++) {
                    checkboxs[i].checked = false;
                }
            }
        });

        $("a[name=downloadExcel]").click(function() {
            var checkboxs = $("input.checkItem");
            var id = "";
            for (var i = 0; i < checkboxs.length; i++) {
                if(checkboxs[i].checked == true){
                    if(id != ""){
                        id += ",";
                    }
                    id += checkboxs[i].name;
                }
            }
            if(id == ""){
                alert("未选择单据");
                $("input[name=checkAll]").focus();
                return false;
            }
            var url = "/admin/coupon/getTable?id=" + id +"&type=qrcode";
            window.location.href = url;
        });

        $("a[name=exportExcel]").click(function() {
            var checkboxs = $("input.checkItem");
            var id = "";
            for (var i = 0; i < checkboxs.length; i++) {
                if(checkboxs[i].checked == true){
                    if(id != ""){
                        id += ",";
                    }
                    id += checkboxs[i].name;
                }
            }
            if(id == ""){
                alert("未选择单据");
                $("input[name=checkAll]").focus();
                return false;
            }
            var url = "/admin/coupon/getTable?id=" + id +"&type=reporting";
            window.location.href = url;
        });
    });
</script>

<form class="well form-search" method="post" style="float:left;width:100%;" action="{:U('coupon/index')}">
    <div class="search_type cc mb10">
        <div class="mb10">
        <span class="mr20">
            &nbsp;&nbsp;&nbsp;<div id="qrcode" style="margin: 0 auto; width: 70%; position: fixed; top: 150px; height: 50px; font-size: 0; line-height: 0; z-index: 100; text-align: right;"></div>

            状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态：{:getEnumSelectWidget($statusEnum, "o#status", $status, 1)}
            &nbsp;CP码：<input type="text" style="width: 90px" name="cp#coupon_code-like" value="{$coupon_code}" />
            &nbsp;产品：
                <select style="width: auto" name="cp#product_id-eq">
                    {:getCommonSelectOptionHtml($product_id, "Product", "product_id", "product_name", null, "coupon_product", 1, "全部")}
                </select>
              &nbsp;渠道：
                <select style="width: auto" name="cp#coupon_hospital_id-eq">
                    {:getCommonSelectOptionHtml($coupon_hospital_id, "CouponHospital", "coupon_hospital_id", "coupon_hospital_name", null, null, 1, "全部")}
                </select>

        <br/>
            微信昵称：<input style="width: 90px" type="text" name="cus#nickname-like" value="{$nickname}" />
              &nbsp;联系人：<input style="width: 90px" type="text" name="o#patient_name-like" value="{$patient_name}" />
            &nbsp;医生：<input style="width: 90px" type="text" name="o#doctor_name-like" value="{$doctor_name}"/>
            &nbsp;医院：<input style="width: 90px" type="text" name="o#hospital_name-like" value="{$hospital_name}"/>
            <br>
            开始时间：<input style="width: 90px" type="text" value="{$begin_time}" class="date J_date" name="o#pay_time-egt" />
            &nbsp;截止时间：<input style="width: 90px" type="text" value="{$end_time}" class="date J_date" name="o#pay_time-elt" />
            &nbsp;<button class="btn btn-primary" type="submit">搜索</button>
            &nbsp;<a class="btn" href="{:U('coupon/index')}">重置</a>
            <br><br>
            每页显示：
            <select name="pageSize" style="color: #1dccaa">
                <option value=''></option>
                <php>$selected=($pageSize == 20)?"selected":"";</php>
                <option value='20' {$selected}>20 条</option>
                <php>$selected=($pageSize == 50)?"selected":"";</php>
                <option value='50' {$selected}>50 条</option>
                <php>$selected=($pageSize == 100)?"selected":"";</php>
                <option value='100' {$selected}>100 条</option>
                <php>$selected=($pageSize == -1)?"selected":"";</php>
                <option value='-1' {$selected}>全部</option>
            </select>

            &nbsp;&nbsp;&nbsp;
            <a style="font-weight: bold;color: #1dccaa">
                【查询结果】
            </a>
            <a style="color: #1dccaa">
                条数：{$totalCount}，
            </a>
            <a style="color: #45a1de">
                成品总数：{$totalNumber}，
            </a>
            <a style="color: #ed7667">
                总金额：{$totalPrice} 元
            </a>
        </span>
        </div>
    </div>
</form>
<div class="wrap J_check_wrap">

    <ul class="nav nav-tabs">
        <li class="active"><a href="{:U('coupon/index')}">列表</a></li>
        <li><a href="{:U('coupon/add')}">新增</a></li>
        <li><a style="color:#de7d74; text-decoration:underline;cursor: pointer;" name="downloadExcel">导出选中二维码Excel</a></li>
        <li>
            <a style="color:#45a1de; text-decoration:underline;" href="https://xwk-file.oss-cn-qingdao.aliyuncs.com/Home/60_40二维码.btw">下载【60_40二维码.btw】</a>
        </li>
        <li><a style="color:#1dccaa; text-decoration:underline;cursor: pointer;" name="exportExcel">导出选中报表Excel</a></li>
    </ul>
    <table class="table table-hover table-bordered">
        <thead>
        <tr>
            <th style="min-width: 10px; width: 10px"><input type="checkbox" name="checkAll"></th>
            <th style="min-width: 50px" width="150px">CP码</th>
            <th style="min-width: 50px" >产品信息</th>
            <th style="min-width: 50px" width="180px">客户信息</th>
            <th style="min-width: 50px" width="150px">备注</th>
            <th style="min-width: 120px">发票信息</th>
            <th>收件信息</th>
            <th style="min-width: 80px" width="90px">医生（医院）</th>
            <th style="min-width: 50px" width="120px">状态</th>
            <th style="min-width: 50px" width="70px">购买时间</th>
            <th style="min-width: 80px">操作</th>
        </tr>
        </thead>
        <tbody>
        <foreach name="orderList" item="vo">
            <tr>
                <php>
                    $checkName = $vo["coupon_id"];
                </php>
                <td><input type="checkbox" class="checkItem" name="{$checkName}"></td>
                <td>
                    <a style="color: #1dccaa">{$vo.coupon_hospital_name}</a>&nbsp;<a style="color: #ed9a63" onmouseover=showQrcode("{$vo.qrcode_url}") onmouseout=showQrcode(0)>{$vo.coupon_code}</a><br/>{$vo.create_time}
                </td>
                <td>
                    <a style="font-weight: bold">{$vo.product_name}</a> x <a style="color: #ed9a63">{$vo.number}</a> 件 <a style="color: #45a1de">【{$vo.supplier_name}】</a>
                    <br/>
                    规格：【<a>{$vo.size}</a>】，单价：<a style="color: #ed7667">{$vo.price}</a> 元
                </td>
                <td>
                    <if condition="$vo['patient_name'] neq ''">
                        联系人：<a style="color: #45a1de">{$vo.patient_name}</a>
                        <br/>
                        微信昵称：<a style="color: #1cc385">{$vo.nickname}</a>
                    </if>
                </td>
                <td>
                    <a style="color: #ffa21c;">{$vo.note}</a><br/>
                </td>
                <td>
                    <if condition="$vo['need_invoice'] neq ''">
                    【{:getEnumString($defaultEnum, $vo['need_invoice'])}】
                    </if>
                    <if condition="$vo['invoice_name'] neq ''">
                        <a style="color: #45a1de">{$vo.invoice_name}</a>
                    </if>
                    <br/>
                    <if condition="$vo['invoice_number'] neq ''">
                        &nbsp;发票号：<a style="color: #45a1de">{$vo.invoice_number}</a>
                    </if>
                </td>
                <td>
                    <a style="color: #45a1de">
                    <if condition="$vo['need_invoice'] gt '0'">
                    {$vo.receive_contact} &nbsp; {$vo.receive_name}
                    <br>
                    {$vo.receive_address}
                    </if>
                    </a>
                </td>
                <td>
                    <if condition="$vo['status'] gt '0'">
                        <a style="color: #45a1de">{$vo.doctor_name}<br/>{$vo.hospital_name}</a>
                        <else/>
                        {$vo.default_doctor_name}<br/>{$vo.default_hospital_name}
                    </if>
                </td>
                <td>
                    <if condition="$vo['status'] eq '-1'">
                        <a style="color: #45a1de;">待付款</a><br/>{$vo.update_time}
                    </if>
                    <if condition="$vo['status'] eq '1' && $vo['need_invoice'] gt '0'">
                        <a style="color: #de7d74">已付款</a><br/>{$vo.pay_time}
                        <elseif condition="$vo['status'] eq 1"/>
                        <a style="color: #1cc385">已售出</a><br/>{$vo.pay_time}
                    </if>
                    <if condition="$vo['status'] eq '2'">
                        <a style="color: #1cc385">发票寄出</a><br/>{$vo.outstock_time}
                    </if>
                </td>
                <td>
                    {$vo.pay_time}
                </td>
                <td>
                    <php>
                        $role = explode(',',$user["role"]);
                        if(in_role($role,"1,8")){
                            $admin = 1;
                        }
                    </php>
                    <if condition="$vo['status'] eq '' && $admin eq '1'">
                        <a class="btn btn-danger" onclick='javascript:del("{$vo.coupon_id}","{$vo.coupon_code}",0)'>作废</a>
                    </if>
                    <if condition="$vo['status'] eq '1' && $vo['need_invoice'] gt '0'">
                        <a class="btn btn-success" href='{:U("order/endDelivery",array("id"=>$vo["order_id"],"home"=>"coupon"))}'>快递发票</a>
                        <!--a class="btn btn-warning" onclick="if(confirm('确认关闭此订单么?')==false)return false;" href='{:U("coupon/closeOrder",array("id"=>$vo["coupon_id"]))}' >关闭订单</a-->
                    </if>
                    <if condition="$vo['status'] eq '2'">
                        <a style="color: #1cc385">
                            {$vo.express_company}
                            <br/>
                            {$vo.delivery_number}
                        </a>
                    </if>
                </td>
            </tr>
        </foreach>
        </tbody>
    </table>
    <div class="pagination">{$page}</div>
</div>
<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>